package com.ruoyi.system.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Games;
import com.ruoyi.system.service.IGamesService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 游戏 信息操作处理
 * 
 * @author ruoyi
 * @date 2019-05-28
 */
@Controller
@RequestMapping("/system/games")
public class GamesController extends BaseController
{
    private String prefix = "system/games";
	
	@Autowired
	private IGamesService gamesService;
	
	@RequiresPermissions("system:games:view")
	@GetMapping()
	public String games()
	{
	    return prefix + "/games";
	}
	
	/**
	 * 查询游戏列表
	 */
	@RequiresPermissions("system:games:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(Games games)
	{
		startPage();
        List<Games> list = gamesService.selectGamesList(games);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出游戏列表
	 */
	@RequiresPermissions("system:games:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Games games)
    {
    	List<Games> list = gamesService.selectGamesList(games);
        ExcelUtil<Games> util = new ExcelUtil<Games>(Games.class);
        return util.exportExcel(list, "games");
    }
	
	/**
	 * 新增游戏
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存游戏
	 */
	@RequiresPermissions("system:games:add")
	@Log(title = "游戏", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(Games games)
	{		
		return toAjax(gamesService.insertGames(games));
	}

	/**
	 * 修改游戏
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") Integer id, ModelMap mmap)
	{
		Games games = gamesService.selectGamesById(id);
		mmap.put("games", games);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存游戏
	 */
	@RequiresPermissions("system:games:edit")
	@Log(title = "游戏", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(Games games)
	{		
		return toAjax(gamesService.updateGames(games));
	}
	
	/**
	 * 删除游戏
	 */
	@RequiresPermissions("system:games:remove")
	@Log(title = "游戏", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(gamesService.deleteGamesByIds(ids));
	}
	
}
